package com.yyx.app1.DiagnosticTools_function.UI;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.yyx.app1.Data.DataInit;
import com.yyx.app1.DiagnosticTools_function.Control.BiochemicalInfo.BiochemicalInfo_Adapter;
import com.yyx.app1.MyApp;
import com.yyx.app1.R;
import com.yyx.app1.tool.ImageTool;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.json.JSONObject;

@EActivity(R.layout.activity_medication)
public class Second_BiochemicalBloodGasAnalysis_Activity extends Activity {
    @ViewById
    ListView medication_listview;

    @ViewById
    ImageView medication_alpha_top,medication_alpha_left,medication_alpha_bottom,web_medication_image,web_medication_image_big;

    @ViewById
    LinearLayout medication_second,medication_name;

    @ViewById
    TextView medication_image_button,medication_medicinename;

    @AfterViews
    public void init()
    {
        try {
            medication_listview.setOverScrollMode(View.OVER_SCROLL_NEVER);
            Intent intent = getIntent();
            String chineseName = intent.getStringExtra("chineseName");
            JSONObject jsonObject = new DataInit(this, false, "cxlin").getRemedyInfo0_SQLiteOperation().getByChineseName(chineseName);
            BiochemicalInfo_Adapter adapter = new BiochemicalInfo_Adapter(this);
            adapter.findAll(jsonObject);
            medication_listview.setAdapter(adapter);
            Drawable drawable = new ColorDrawable(Color.WHITE);
            drawable.setAlpha(0);
            medication_listview.setDivider(null);
            medication_listview.setDividerHeight(5);
            medication_medicinename.setText(chineseName);
            String image = jsonObject.getString("");
            if (image !=null || !image.isEmpty())
            {
                //缺少
            }
            else
            {
                Bitmap bitmap = ((MyApp) getApplication()).getBaseDataManager().getResDrawable(R.drawable.medication, ImageTool.dip2px(this,150), ImageTool.dip2px(this,150));
                web_medication_image.setImageBitmap(bitmap);
                web_medication_image_big.setImageBitmap(bitmap);
            }
        }catch (Exception e)
        {
            Log.e("异常1511061403",e.toString());
        }
    }

    @Click({R.id.medication_alpha_top,R.id.medication_alpha_left,R.id.medication_alpha_bottom})
    public void gotogone()
    {
        medication_second.setVisibility(View.GONE);
    }

    @Click
    public void medication_name()
    {
        medication_second.setVisibility(View.VISIBLE);
    }

    @Click
    public void medication_image_button()
    {
        medication_second.setVisibility(View.VISIBLE);
    }

    @Click
    public void home()
    {
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            home();
        }
        return true;
    }
}

